﻿namespace ThingsGateway.Foundation
{

    public abstract class ReadWriteDevicesUdpClientBase : ReadWriteDevicesClientBase
    {

        public UdpSession UdpSession;

        public ReadWriteDevicesUdpClientBase(UdpSession udpSession)
        {
            UdpSession = udpSession;
            SetDataAdapter();
        }

        public override string ToString()
        {
            return UdpSession.RemoteIPHost.ToString();
        }
        public override OperResult<byte[]> Send(byte[] data, WaitingOptions waitingOptions = WaitingOptions.NoneAll)
        {
            try
            {
                ResponsedData result = UdpSession.GetWaitingClient(waitingOptions).SendThenResponse(data, TimeOut, CancellationToken.None);
                return OperResult.CreateSuccessResult(result.Data);
            }
            catch (Exception ex)
            {
                return new OperResult<byte[]>(ex);
            }
        }


    }
}
